package leetcode.list;

import utils.node.ListNode;

/**
 * @Description: https://leetcode.cn/problems/intersection-of-two-linked-lists/
 * @Author Ammar
 * @Create 2023/7/10 17:54
 */
public class _160_相交链表 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode curA = headA, curB = headB;
        while (curA != curB) {
            curA = (curA == null) ? headB : curA.next;
            curB = (curB == null) ? headA : curB.next;
        }
        return curA;
    }
}
